<template>
  <el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
          <el-form-item label="用户ID" prop="userId">
          <el-input v-model="dataForm.userId" placeholder="用户ID"></el-input>
      </el-form-item>
          <el-form-item label="内部订单号" prop="orderNo">
          <el-input v-model="dataForm.orderNo" placeholder="内部订单号"></el-input>
      </el-form-item>
          <el-form-item label="业务类型 BUY_GOODS:商城消费 BUY_SCORE:购买积分 RECHARGE:充值 UPGRADE:升级" prop="businessType">
          <el-input v-model="dataForm.businessType" placeholder="业务类型 BUY_GOODS:商城消费 BUY_SCORE:购买积分 RECHARGE:充值 UPGRADE:升级"></el-input>
      </el-form-item>
          <el-form-item label="支付类型 1-aipay微信 2-aipay支付宝 3-aipay快捷" prop="payType">
          <el-input v-model="dataForm.payType" placeholder="支付类型 1-aipay微信 2-aipay支付宝 3-aipay快捷"></el-input>
      </el-form-item>
          <el-form-item label="商户号" prop="ino">
          <el-input v-model="dataForm.ino" placeholder="商户号"></el-input>
      </el-form-item>
          <el-form-item label="支付金额" prop="payMoney">
          <el-input v-model="dataForm.payMoney" placeholder="支付金额"></el-input>
      </el-form-item>
          <el-form-item label="支付流水单号" prop="outTradeNo">
          <el-input v-model="dataForm.outTradeNo" placeholder="支付流水单号"></el-input>
      </el-form-item>
          <el-form-item label="请求数据" prop="request">
          <el-input v-model="dataForm.request" placeholder="请求数据"></el-input>
      </el-form-item>
          <el-form-item label="支付成功返回的数据" prop="response">
          <el-input v-model="dataForm.response" placeholder="支付成功返回的数据"></el-input>
      </el-form-item>
          <el-form-item label="响应时间" prop="responseTime">
          <el-input v-model="dataForm.responseTime" placeholder="响应时间"></el-input>
      </el-form-item>
          <el-form-item label="状态 0未请求第三方接口  1已获取支付链接或跳入快捷页面 2已接收到异步响应 3处理完回调方法 4处理失败 5重复支付" prop="payStatus">
          <el-input v-model="dataForm.payStatus" placeholder="状态 0未请求第三方接口  1已获取支付链接或跳入快捷页面 2已接收到异步响应 3处理完回调方法 4处理失败 5重复支付"></el-input>
      </el-form-item>
          <el-form-item label="0：正常；1：手动补单" prop="handleStatus">
          <el-input v-model="dataForm.handleStatus" placeholder="0：正常；1：手动补单"></el-input>
      </el-form-item>
          <el-form-item label="备注" prop="remark">
          <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
      </el-form-item>
          <el-form-item label="删除标记 0删除 1显示）" prop="dataFlag">
          <el-input v-model="dataForm.dataFlag" placeholder="删除标记 0删除 1显示）"></el-input>
      </el-form-item>
          <el-form-item label="创建时间" prop="createTime">
          <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
      </el-form>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
import debounce from 'lodash/debounce'
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        id: '',
        userId: '',
        orderNo: '',
        businessType: '',
        payType: '',
        ino: '',
        payMoney: '',
        outTradeNo: '',
        request: '',
        response: '',
        responseTime: '',
        payStatus: '',
        handleStatus: '',
        remark: '',
        dataFlag: '',
        createTime: ''
      }
    }
  },
  computed: {
    dataRule () {
      return {
        userId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        orderNo: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        businessType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        payType: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        ino: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        payMoney: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        outTradeNo: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        request: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        response: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        responseTime: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        payStatus: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        handleStatus: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        remark: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        dataFlag: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.getInfo()
        }
      })
    },
    // 获取信息
    getInfo () {
      this.$http.get(`/demo/xlslogthirdpay/${this.dataForm.id}`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      }).catch(() => {})
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.$http[!this.dataForm.id ? 'post' : 'put']('/demo/xlslogthirdpay/', this.dataForm).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        }).catch(() => {})
      })
    }, 1000, { 'leading': true, 'trailing': false })
  }
}
</script>
